package org.spring.aicloud.controller;

import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.spring.aicloud.entity.Comment;
import org.spring.aicloud.service.ICommentService;
import org.spring.aicloud.util.ResponseEntity;
import org.spring.aicloud.util.SecurityUtil;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/comment")
@Tag(name = "评论控制器")
public class CommentController {

    @Resource
    private ICommentService commentService;

    /**
     *  添加评论
     */
    @RequestMapping("/add")
    public ResponseEntity add(@Validated Comment comment){
        //给传来的comment对象中uid赋值
        comment.setUid(SecurityUtil.getCurrentUser().getUid());
        boolean save = commentService.save(comment);
        if (!save){
            return ResponseEntity.fail("添加失败");
        }
        return ResponseEntity.success(save);
    }
}
